package cn.magic0610.realtime;

import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.command.TabExecutor;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class RtCommand implements TabExecutor {
    @Override
    public boolean onCommand(CommandSender sender, Command cmd, String s, String[] args) {
        if (args.length != 1) {
            sender.sendMessage("§c使用 /rt reload 以重载配置文件！");
            return true;
        }
        if (args[0].equalsIgnoreCase("reload")) {
            Functions functions = new Functions();
            functions.load();
            sender.sendMessage("§a配置文件重载完成！");
        } else {
            sender.sendMessage("§c使用 /rt reload 以重载配置文件！");
        }
        return true;
    }

    @Override
    public List<String> onTabComplete(CommandSender sender, Command cmd, String s, String[] args) {
        if (args.length == 1) {
            List<String> result = new ArrayList<>(Collections.singletonList("reload"));
            result.removeIf(r -> !r.startsWith(args[0].toLowerCase()));
            return result;
        } else {
            return new ArrayList<>();
        }
    }
}
